﻿export function init(editorId, dotNetHelper, options) {
    const el = document.getElementById(editorId);
    const cm = CodeMirror.fromTextArea(el, {
        lineNumbers: true,
        ...options
    });

    const codeMirrorEl = el.parentElement.querySelector('.CodeMirror');
    if (options.rowCount > 0) {
        codeMirrorEl.style.height = `${options.rowCount * 12}px`;
    }
    codeMirrorEl.style.fontFamily = 'consolas';
    codeMirrorEl.style.border = '1px solid #ced4da';
    codeMirrorEl.style.borderRadius = '2px';

    cm.on('blur', function () {
        dotNetHelper.invokeMethodAsync('SetCodeAsync', cm.getValue());
        codeMirrorEl.style.borderColor = '#ced4da';
    });

    cm.on('focus', function () {
        codeMirrorEl.style.borderColor = '#ffb884';
    });
}
